/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.pdx.cs.guavadata.subclass;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author VuTran
 */
public class DataTable {
    String name;
    public List<DataColumn> columns;
    public List<Map<String, Object>> rows;
    
    public static int ROW_DELETE = 0;
    public static int ROW_INSERT = 1;
    public static int ROW_UPDATE = 2;
    public static int ROW_NORMAL = 3;
    public static int ROW_INSERT_DELETE = 4; // case insert and then delete before commit
    public static String ROW_STATE = "ROW_STATE";

    public DataTable() {
        columns = new ArrayList<DataColumn>();
        rows = new ArrayList<Map<String, Object>>();
    }

    public DataTable(String name) {
        this.name = name;
        columns = new ArrayList<DataColumn>();
        rows = new ArrayList<Map<String, Object>>();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public DataTable getDataView(String key, String value) {
        DataTable dt = new DataTable();
        dt.columns = new ArrayList<DataColumn>(columns);
        if (!value.equals("%")) {
            for (Map<String, Object> row : this.rows) {
                if (row.get(key).toString().equalsIgnoreCase(value)) {
                    dt.rows.add(row);
                }
            }
        }
        return dt;
    }
}
